package com.vast.ui.component.models;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.ListenerList;

public class ItemPanel {
	private final  List<ItemArray> itemArrayList;
	private final  ListenerList listenerList;
	private int    column;

	public ItemPanel() {
		this.itemArrayList = new ArrayList<ItemArray>();
		this.listenerList  = new ListenerList();
	}
	
	public List<ItemArray> getList(){
		return itemArrayList;
	}
	
	public void add(ItemArray itemArray){
		itemArray.putLineNumber(itemArrayList.size());
		itemArrayList.add(itemArray);
		column = itemArray.size();
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((ItemArrayListener) listener).add(itemArray);
		}
	}
	
	public void remove(ItemArray itemArray){
		itemArrayList.remove(itemArray);
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((ItemArrayListener) listener).remove(itemArray);
		}
	}
	
	public void addListener(ItemArrayListener listener){
		listenerList.add(listener);
	}
	
	public void removeListener(ItemArrayListener listener){
		listenerList.remove(listener);
	}
	
	public ItemArray getTarget(int index) {
		return itemArrayList.get(index);
	}
	
	public void setTarget(int index, ItemArray itemArray) {
		itemArrayList.set(index,itemArray);
	}
	
	public void clear() {
		itemArrayList.clear();
		listenerList.clear();
	}
	
	public int getNumberOfColumn(){
		return column;
	}
}
